package com.ec.vs.controller;

import com.ec.common.domain.Result;
import com.ec.vs.vo.VsAppointmentVo;
import com.ec.vs.service.VsExploreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员-参观预约")
@RestController
@RequestMapping("/visit/admin/explore")
@RequiredArgsConstructor
@Slf4j
public class AdminExploreController {

    private final VsExploreService vsExploreService;

    @ApiOperation("分页查询【参观】预约")
    @GetMapping
    public Result<Object> list(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String mobile,
            @RequestParam(required = false) String status,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return vsExploreService.listExploreAppointments(name, mobile, status, page, size);
    }

    @ApiOperation("审核通过【参观】预约")
    @PutMapping("/{id}/approve")
    public Result<String> approve(@PathVariable Long id) {
        int rows = vsExploreService.approveExploreAppointment(id);
        return rows > 0 ? Result.ok("审核成功") : Result.error("审核失败，请确认预约状态为待确定");
    }

    @ApiOperation("取消【参观】预约")
    @PostMapping("/{id}/cancel")
    public Result<String> cancel(@PathVariable Long id) {
        int rows = vsExploreService.cancelExploreAppointment(id);
        return rows > 0 ? Result.ok("取消成功") : Result.error("取消失败");
    }

    @ApiOperation("删除【参观】预约")
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Long id) {
        int rows = vsExploreService.deleteExploreAppointment(id);
        return rows > 0 ? Result.ok("删除成功") : Result.error("删除失败，预约不存在");
    }

    @ApiOperation("新增【参观】预约")
    @PostMapping
    public Result<String> create(@Valid @RequestBody VsAppointmentVo vo) {
        int rows = vsExploreService.createExploreAppointment(vo);
        return rows > 0 ? Result.ok("新增成功") : Result.error("新增失败");
    }
}